<?php
require("GTranslate.php");
 

function array_to_json_string($arraydata) {
		$output = "";
		$output .= "[";
		 $i = 1;
		 
		foreach($arraydata as $key=>$val){
		
			   if (count($arraydata)==$i){
			   // $output .= "['".$val."' , '".$key."' , 'ux-flag-".$val."']";
			      $output .= "['".$val."' , '".$key."']";
			   }else{
				//$output .= "['".$val."' , '".$key."' , 'ux-flag-".$val."'],";
				$output .= "['".$val."' , '".$key."'],";
				}
				$i++;
		}  
		$output .= "]";
		return $output;
	}
	
 try{
       $gt = new Gtranslate;
       
       if ($_GET['cmd']=='languages') {
	   		echo array_to_json_string($gt->available_languages);
	   } 

 if ($_GET['cmd']=='translate') {
      if (isset($_GET['translate']) && isset($_GET['language'])) {
      	    
	        $lang_pair = array('english', $_GET['language']);
	        
	   		echo $gt->query( $gt->isValidLanguage($lang_pair ) ,$_GET['translate']);
	   } 
	}   
	   
 } catch (GTranslateException $ge)
 {
       echo $ge->getMessage();
 }

?>
